import { request } from '../utils'
import { Toast } from 'vant'

/*
  物流信息
*/
const getExpressInfo = (requestData, cb) => {
  request({
    url: "api/MemberOrder/GetExpressInfo",
    params: requestData,
  }).then((res) => {
    if (res.data.Success) {
      cb && cb(res.data.Data)
    } else {
      console.log("获取物流信息错误...")
      Toast(res.data.Msg)
    }
  })
}

/*
  订单收货
*/
const receiveOrder = (requestData, cb) => {
  request({
    method: 'POST',
    url: "api/MemberOrder/PostConfirmOrder",
    data: requestData,
  }).then((res) => {
    if (res.data.Success) {
      cb && cb(res.data.Data)
    } else {
      console.log("确认收货失败...")
      Toast(res.data.Msg)
    }
  })
}

/*
  取消订单
*/
const cancelOrder = (requestData, cb) => {
  request({
    method: "POST",
    url: "api/MemberOrder/PostCloseOrder",
    data: requestData,
  }).then((res) => {
    if (res.data.Success) {
      cb && cb(res.data.Data)
    } else {
      console.log("取消订单失败...")
      Toast(res.data.Msg)
    }
  })
}

/*
  获取订单评价
*/
const getComment = (requestData, cb) => {
  request({
    url: "api/Comment/GetComment",
    params: requestData,
  }).then((res) => {
    if (res.data.Success) {
      cb && cb(res.data.Data)
    } else {
      console.log("获取订单评价失败...")
      Toast(res.data.Msg)
    }
  })
}

/*
  退款
*/
const refundOrder = (requestData, cb) => {
  request({
    method: "POST",
    url: "api/OrderRefund/PostRefundApply",
    data: requestData,
  }).then((res) => {
    if (res.data.Success) {
      cb && cb()
    } else {
      console.log("订单退款失败...")
      Toast(res.data.Msg)
    }
  })
}

/*
  用户提交退回商品快递信息
*/
const postSellerSendGoods = (requestData, cb) => {
  request({
    method: "POST",
    url: "api/OrderRefund/PostSellerSendGoods",
    data: requestData,
  }).then((res) => {
    if (res.data.Success) {
      cb && cb()
    } else {
      console.log("提交快递信息失败...")
      Toast(res.data.Msg)
    }
  })
}

/*
  获取售后列表
*/
const getRefundList = (cb) => {
  request({
    url: "api/OrderRefund/GetRefundList",
    params: {
      userkey: localStorage.getItem("userKey"),
      pageNo: 1,
      pageSize: 1000,
    },
  }).then((res) => {
    if (res.data.Success) {
      cb && cb(res.data.Data.data)
    } else {
      console.log("获取售后订单失败...")
      Toast(res.data.Msg)
    }
  })
}

/*
  获取售后详情
*/
const getRefundDetail = (requestData, cb) => {
  request({
    url: "api/OrderRefund/GetRefundDetail",
    params: requestData,
  }).then((res) => {
    if (res.data.Success) {
      cb && cb(res.data.Data)
    } else {
      console.log("获取售后订单失败...")
      Toast(res.data.Msg)
    }
  })
}

export {
  getExpressInfo,
  receiveOrder,
  getComment,
  cancelOrder,
  refundOrder,
  getRefundList,
  getRefundDetail,
  postSellerSendGoods,
}